package com.itheima.ssm.controller;

import com.itheima.ssm.pojo.User;
import com.itheima.ssm.service.impl.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class UserController {

    @Autowired
    private UserService userService;
    @RequestMapping("user")
    public String toUser() {
        System.out.println("hello");
        return "user";
    }

    @RequestMapping("showUser")
    public String findUserById(Model model,Long id) {
        User user = userService.findUserById(id);
        model.addAttribute("user",user);
        return "user";
    }

    @RequestMapping("deleteUser")
    public String deleteUserById(@RequestParam("id") Long id) {
        userService.deleteUserByid(id);
        return "user";
    }
}
